package com.baidu.util;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @author 田甜
 * @version 1.0
 * @description: TODO
 * @date 2021/12/15 0015 9:44
 */
public class FacePeople {


    //人脸识别判断输入必要参数姓名身份证和身份证照片

        //public static void main(String[] args) throws IOException {
        //    String url = "https://faceidcardb.shumaidata.com/getfaceidb";
        //    String appCode = "5458f6797b984b4f9595b34f796b0349";
        //    Map<String, String> params = new HashMap<>();
        //    params.put("idcard", "230523198910304814");
        //    params.put("name", "孙雷");
        //    //image 和 url 二选一 ，选择其中一个时，请注释另外一个参数,默认使用image
        //    params.put("url", "https://tse1-mm.cn.bing.net/th/id/R-C.f3d27b91da3abb09f1f5b627edda68e1?rik=nCvJ1cDhHOJiFg&riu=http%3a%2f%2fwww.ygjj.com%2fbookpic2%2f2013-12-19%2fnew507321-20131219212949655484.jpg&ehk=PSrAWvNlOtMpxm5MDtbPTSTgSfAibwQ8PSwwjuEZ%2b2A%3d&risl=&pid=ImgRaw&r=0");
        //    //params.put("image", "");
        //    String result = postForm(appCode, url, params);
        //    System.out.println(result);
        //}
        /**
         * 用到的HTTP工具包：okhttp 3.13.1
         * <dependency>
         * <groupId>com.squareup.okhttp3</groupId>
         * <artifactId>okhttp</artifactId>
         * <version>3.13.1</version>
         * </dependency>
         */
        public static String postForm(String appCodes, String urls, Map<String, String> paramss) throws IOException {
            OkHttpClient client = new OkHttpClient.Builder().build();
            FormBody.Builder formbuilder = new FormBody.Builder();
            Iterator<String> it = paramss.keySet().iterator();
            while (it.hasNext()) {
                String key = it.next();
                formbuilder.add(key, paramss.get(key));
            }
            FormBody body = formbuilder.build();
            Request request = new Request.Builder().url(urls).addHeader("Authorization", "APPCODE " + appCodes).post(body).build();
            Response response = client.newCall(request).execute();
            System.out.println("返回状态码" + response.code() + ",message:" + response.message());
            String result = response.body().string();
            return result;
        }
}
